package com.senven.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.senven.api.commom.ResponsePage;
import com.senven.api.dao.GoodsMapper;
import com.senven.api.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cckimjs
 *
 */
@Service
public class GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    public ResponsePage<Goods> queryGoodsList(int current, int size){
        Page<Goods> page = new Page<Goods>(current, size);
        QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>();

        IPage<Goods> iPage = goodsMapper.selectPage(page, null);

        ResponsePage<Goods> responsePage= new ResponsePage<Goods>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     *根据OID查询社团物资
     * @param oid
     * @return
     */
    public Goods queryGoodsListByOid(int oid){
        return goodsMapper.queryGoodsListByOid(oid);
    }

    /**
     * 根据名字查询社团物资
     * 要求前缀正确
     * @param name
     * @return
     */
    public ResponsePage<Goods> queryGoodsListByName(String name,int current, int size){
        Page<Goods> page = new Page<Goods>(current, size);
        QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>();
        wrapper.like("name",name);

        IPage<Goods> iPage = goodsMapper.selectPage(page, wrapper);

        ResponsePage<Goods> responsePage= new ResponsePage<Goods>();
        responsePage.makePage(iPage);

        return responsePage;
    }

    /**
     * 插入一个社团物资
     * @param goods
     * @return
     */
    public int insertGoods(Goods goods){return goodsMapper.insertGoods(goods);};

    /**
     * 更新一个社团物资的信息
     */
    public int updateGoods(Goods goods){return goodsMapper.updateById(goods);}

    /**
     *
     * 删除一个社团物资的信息
     */
    public int deleteGoods(int oid){return goodsMapper.deleteGoods(oid);}

}
